package mysql

import "gorm.io/gorm"

type Shop struct {
	gorm.Model
	Title  string  `form:"type:varchar(30)" json:"title,omitempty"`
	Info   string  `form:"type:varchar(30)" json:"info,omitempty"`
	Price  float64 `form:"type:decimal(10,2)" json:"price,omitempty"`
	Num    int64   `form:"type:int(11)" json:"num,omitempty"`
	Image  string  `form:"type:varchar(200)" json:"image,omitempty"`
	UserId int     `form:"type:int(11)" json:"userId,omitempty"`
	Audit  int     `form:"type:int(11)comment 1 审核通过 2 审核未通过 3 未审核" json:"audit,omitempty"`
	Status int     `form:"type:int(11)" json:"status,omitempty"`
}

func (s *Shop) Create() error {
	return DB.Create(&s).Error
}
func (s *Shop) Update() error {
	return DB.Updates(&s).Error
}
func (s *Shop) ShowList() error {
	return DB.Where("id  = ?", s.ID).Limit(1).Find(&s).Error
}
func (s *Shop) Find() error {
	return DB.Where("id = ?", s.ID).Limit(1).Find(&s).Error
}
func (s *Shop) GetByUserId() error {
	return DB.Where("user_id = ?", s.UserId).Limit(1).Find(&s).Error
}
func (s *Shop) HousPriceList(max, min float64) (houselist []*Shop, err error) {
	db := DB
	if max > min {
		db = db.Where("price <= ?", max)
	}
	if min >= 1000000 {
		db.Where("price >= ?", min)
	}
	err = db.Order("create_at desc").Find(&houselist).Error
	return
}
